package com.ruoyi.wq.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.Condition;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysUserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wq.mapper.WqPlayOrderMapper;
import com.ruoyi.wq.domain.WqPlayOrder;
import com.ruoyi.wq.domain.vo.WqPlayOrderVO;
import com.ruoyi.wq.service.IWqPlayOrderService;

/**
 * 陪玩订单Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-09-11
 */
@Service
public class WqPlayOrderServiceImpl extends ServiceImpl<WqPlayOrderMapper, WqPlayOrder> implements IWqPlayOrderService {

    @Autowired
    private WqPlayOrderMapper wqPlayOrderMapper;
    
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询陪玩订单
     * 
     * @param id 陪玩订单主键
     * @return 陪玩订单
     */
    @Override
    public WqPlayOrder selectWqPlayOrderById(String id)
    {
        return wqPlayOrderMapper.selectWqPlayOrderById(id);
    }

    /**
     * 查询陪玩订单列表
     * 
     * @param wqPlayOrder 陪玩订单
     * @return 陪玩订单
     */
    @Override
    public List<WqPlayOrder> selectWqPlayOrderList(WqPlayOrder wqPlayOrder)
    {
        return wqPlayOrderMapper.selectWqPlayOrderList(wqPlayOrder);
    }

    /**
     * 新增陪玩订单
     * 
     * @param wqPlayOrder 陪玩订单
     * @return 结果
     */
    @Override
    public int insertWqPlayOrder(WqPlayOrder wqPlayOrder)
    {
        wqPlayOrder.setCreateTime(DateUtils.getNowDate());
        return wqPlayOrderMapper.insertWqPlayOrder(wqPlayOrder);
    }

    /**
     * 修改陪玩订单
     * 
     * @param wqPlayOrder 陪玩订单
     * @return 结果
     */
    @Override
    public int updateWqPlayOrder(WqPlayOrder wqPlayOrder)
    {
        wqPlayOrder.setUpdateTime(DateUtils.getNowDate());
        return wqPlayOrderMapper.updateWqPlayOrder(wqPlayOrder);
    }

    /**
     * 批量删除陪玩订单
     * 
     * @param ids 需要删除的陪玩订单主键
     * @return 结果
     */
    @Override
    public int deleteWqPlayOrderByIds(String[] ids)
    {
        return wqPlayOrderMapper.deleteWqPlayOrderByIds(ids);
    }

    /**
     * 删除陪玩订单信息
     * 
     * @param id 陪玩订单主键
     * @return 结果
     */
    @Override
    public int deleteWqPlayOrderById(String id)
    {
        return wqPlayOrderMapper.deleteWqPlayOrderById(id);
    }

	@Override
	public TableDataInfo getPageList(WqPlayOrderVO wqPlayOrder) {
		SysUser user = sysUserService.getById(SecurityUtils.getUserId());
		if("0".equals(user.getIsManager())){
			wqPlayOrder.setUserId(user.getUserId());
			wqPlayOrder.setOrderType(user.getPlayStatus());
		}
		IPage<WqPlayOrderVO> page = baseMapper.selectPageList(Condition.getPage(wqPlayOrder), wqPlayOrder);
		for(WqPlayOrderVO vo : page.getRecords()){
			vo.setBossFlag(false);
			vo.setShareFlag(false);
			vo.setPlayFlag(false);
			if("0".equals(user.getPlayStatus())){
				vo.setShareFlag(true);
			}
			if("2".equals(user.getPlayStatus())){
				vo.setBossFlag(true);
				vo.setPlayFlag(true);
			}
			if("1".equals(user.getIsManager())){
				vo.setBossFlag(true);
				vo.setShareFlag(true);
				vo.setPlayFlag(true);
			}
		}
		return Condition.getTableDataInfo(page.getRecords(), page.getTotal());
	}

	@Override
	public Long getCashByUserId(Long userId, String orderType) {
		WqPlayOrderVO playOrder = new WqPlayOrderVO();
		playOrder.setUserId(userId);
		playOrder.setOrderType(orderType);
		return baseMapper.getCashByUserId(playOrder);
	}
}
